import { Model } from 'react-model'

interface UserInfoType {
  nickName: string
  avatarUrl: string
}

interface StateType {
  firstBtn: number
  secondBtn: number
  keyword: string
  videoSecondType: Array<number>
  personalMsg: UserInfoType
}

interface ActionType {
  toSaveChoosedBtn: any
  toSaveSearchWord: string
  toSaveVideoSecondType: Array<number>
  toSaveToken: UserInfoType
}

const initialState = {
  firstBtn: 0,
  secondBtn: 0,
  keyword: '',
  videoSecondType: [],
  personalMsg: {
    nickName: '',
    avatarUrl: ''
  }
}

const model: ModelType<StateType, ActionType> = {
  actions: {
    async toSaveChoosedBtn(choosedBtn) {
      return {
        firstBtn: choosedBtn.firstBtn,
        secondBtn: choosedBtn.secondBtn
      }
    },
    async toSaveSearchWord(searchWord) {
      return {
        keyword: searchWord
      }
    },
    async toSaveVideoSecondType(videoSecondType) {
      return {
        videoSecondType
      }
    },
    async toSaveToken(data) {
      return {
        personalMsg: data
      }
    }
  },
  state: initialState
}

export default Model(model)
